<?php

/////////////////////////////////////
//////                         //////
//////    PAGE PRINCIPALE      ////// 
//////                         //////
/////////////////////////////////////    

// inclure "settings.php" pour les valeurs de config
include_once("config/general.config.php");

// on instancie le wrapper Facebook
$facebook = new Facebook($appId_SETTINGS, $appSecret_SETTINGS, $postAuthUrl_SETTINGS, $permissionsArray_SETTINGS);


// afficher les albums photos
// $query = 'SELECT aid, owner, name, object_id FROM album WHERE owner=me()';


// Montrer toutes les photos présentes dans les albums de user et celles où user est taggé
// Classer par nombre de likes
// renvoyer la première (OFFSET 0 = à partir de la photo index 0)
$query =   'SELECT object_id, pid, aid, owner, src_small, like_info, comment_info 
			FROM photo 
			WHERE aid IN (SELECT aid FROM album WHERE owner=me())
			OR object_id IN (SELECT object_id FROM photo_tag WHERE subject=me())
			AND object_id != 428496596854
			ORDER BY like_info DESC
			LIMIT 3 OFFSET 0';

// $query = "SELECT src_small, pid FROM photo WHERE object_id IN (SELECT object_id FROM like WHERE user_id=me())";

$query = $facebook->sendAPISingleQuery($query);
$arrayObjectId = array();

$i = 0;

foreach ($query['data'] as $photo) {
	
	echo "<br><strong>****************</strong></br>";
	echo "<p><img src='".$photo['src_small']."'></p>";
	echo "<pre>".print_r($photo)."</pre>";
	
	$arrayObjectId[$i] = number_format($photo['object_id'], '.', '', '');
	// la fonction "number_format" permet de convertir les object_id reçues en notation scientifique
	// en nombre courant. Les parametres '.' convertir les virgules de décimale en point,
	// et les parametres '' et '' evite que l'on mettre des espaces pour marquer les centaines et les milliers
	
	$i++;
}

$result = $facebook->getItemsInfos($arrayObjectId);
if ($result) {$facebook->displayAPIQuery($result);}
else {echo "<h1>ERREUR</h1>";}



	



// echo "<h1>".$i."</h1>";

//////////

// $query = 'SELECT pid FROM photo_tag WHERE subject=me()';




$facebook->displayAPIQuery($query);

// echo "<strong>************</strong>";

// for ($i=0;$i<50;$i++) {
	
// 	$facebook->displayAPIQuery($facebook->getFeed($i));
// 	echo "<p><strong>*****************************************************</strong></p>";	
	
// }




// $facebook->getFeed();

// $arrayQuery = array("all friends" => "SELECT uid2 FROM friend WHERE uid1=me()", "my name" => "SELECT name FROM user WHERE uid=me()");
// $facebook->displayAPIQuery($facebook->sendAPIMultyQuery($arrayQuery));

?>


<!doctype html>
<html>

	<head>
 		<title></title>
	</head>

	
<body>
</body>

</html>
